import pytest
from page.mialList import MailListPage
from selenium.webdriver.common.by import By
from tools.readYaml import read_yaml
from tools.myLogger import logger
import allure
from page import MailListPageElement

org_create_datas = read_yaml("./caseData/mailList/org_manage.yaml", "org_create")
org_update_datas = read_yaml("./caseData/mailList/org_manage.yaml", "org_update")

@allure.epic("通讯录管理")
@allure.feature("组织管理")
class TestOreg():

    @allure.story("创建组织")
    @allure.title("{title}")
    @pytest.mark.parametrize("title, case_data", [(case_data['title'], case_data) for case_data in org_create_datas])
    def test_create_org(self, login_and_quit, title, case_data):
        logger.info("开始运行测试用例：{}".format(case_data['title']))
        self.page = MailListPage(login_and_quit)
        with allure.step("进入通讯录页面"):
            self.page.get_mail_list_page()
        self.page.add_org(case_data.get('data').get('org_name'), case_data.get("data").get("parent_org"))
        with allure.step("判断报错信息是否正确"):
            assert self.page.get_text(MailListPageElement.tips_manager) == case_data.get("expect")

    @allure.story("修改部门名称")
    @allure.title("{title}")
    @pytest.mark.parametrize("title, case_data", [(case_data["title"], case_data) for case_data in org_update_datas])
    def test_update_org(self, login_and_quit, title, case_data):
        logger.info("开始运行测试用例：{}".format(title))
        self.page = MailListPage(login_and_quit)
        with allure.step("进入通讯录页面"):
            self.page.get_mail_list_page()
        self.page.update_org(**case_data['data'])
        with allure.step("判断报错信息是否正确"):
            assert self.page.get_text(MailListPageElement.tips_manager) == case_data.get("expect")

